<template>
  <div class="content-row">
    <div class="photo-box">
      <div class="photo-title">
        <span>上传图片：</span>
      </div>
      <ul class="photo-list">
        <li class="photo-item" v-for="(item, index) in reviewPhotoList" :key="index">
          <img class="photo" :src="item.src" alt="" @click="showPic">
          <img :src="item.src" alt="" style="display:none" class="photoHide">
        </li>
      </ul>
      <vue-preview class="review-pic-list" :slides="picList" @close="close"></vue-preview>
    </div>
    <photo-preview />

  </div>
</template>
<script>
import PhotoPreview from './PhotoPreview'
export default {
  name: "",
  data: () => ({
    reviewPhotoList: [
      { src: 'http://localhost:8082/static/img/image1.png', msrc: 'http://localhost:8082/static/img/image1.png', w: 200, h: 200 },
      { src: 'https://bigdata.byd.com/appInterface/viewImage.do?key=http://10.54.18.136:8081/seriesImg/upload//201808/3GO1ISJOPJ1KTS0NVBX2B2ZT10N4O0K/277c640f-6d25-48a8-b634-6b5704b4b1dd.jpg', msrc: 'https://bigdata.byd.com/appInterface/viewImage.do?key=http://10.54.18.136:8081/seriesImg/upload//201808/3GO1ISJOPJ1KTS0NVBX2B2ZT10N4O0K/277c640f-6d25-48a8-b634-6b5704b4b1dd.jpg', w: 200, h: 200 }
    ],
    picList: []
  }),
  methods: {
    close () {

    },
    showPic (e) {
      const el = e.target
      const hideEl = el.parentNode.querySelector('.photoHide')
      let width = 0
      let height = 0
      const winWidth = window.innerWidth
      const winHeight = window.innerHeight
      if (hideEl.width >= hideEl.height) {
        width = hideEl.width > winWidth ? winWidth : hideEl.width
        height = hideEl.height * (width / hideEl.width)
      } else {
        height = hideEl.height > winHeight ? winHeight : hideEl.height
        width = hideEl.width * (height / hideEl.height)
      }
      const src = el.src
      const pswpElement = document.querySelectorAll('.pswp')[0]
      const photoList = [
        {
          src,
          msrc: src,
          w: width,
          h: height
        }
      ]
      const options = {
        fullscreenEl: false,
        tapToClose: true,
        shareEl: false
      }
      const gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, photoList, options)
      gallery.init()
    }
  },
  components: {
    PhotoPreview
  }
}
</script>
<style lang="scss" scoped>
$border: #D9D9D9;
$grey: #666666;
$blue: #078DFF;
$red: #F40226;
$white: #FFFFFF;
$green: #05C911;
$orange: #FC6932;
$purple: #7971ea;
.content-row {
  width: 90%;
  margin: auto;
}
.photo-box {
  font-size: .25rem;
  margin-bottom: .3rem;
  border: 1px solid $border;
  padding: .2rem;
}
.photo-box {
  min-height: 2rem;
  .photo-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .1rem;
    color: #000;
  }
  .photo-list {
    display: flex;
    flex-wrap: wrap;
    .photo-item {
      width: 1.2rem;
      height: 1.2rem;
      margin-right: .3rem;
      background-color: #dddddd;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
      &.add-btn {
        font-size: .7rem;
      }
      .remove-btn {
        position: absolute;
        right: -.1rem;
        top: -.1rem;
        $closeHeight: .35rem;
        width: $closeHeight;
        height: $closeHeight;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        font-size: .28rem;
        background-color: $red;
        color: $white;
        opacity: .8;
      }
    }
  }
}
</style>
<style lang="scss">
.review-pic-list {
  width: 100%;
  .my-gallery {
    width: 100%;
    display: flex;
  }
  figure {
    width: 1.2rem;
    height: 1.2rem;
    margin-right: .3rem;
    background-color: #dddddd;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    img {
      width: 100%;
    }
  }
}
</style>
